package test.quiz2;

import day11.ThreadPool;
import test.day214.TimeThread;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class WRitT1 {
    public static void main(String[] args) throws IOException {
        FileWriter fw = new FileWriter("out.txt", true);
        Scanner in = new Scanner(System.in);
        TimeThread th = new TimeThread();
        th.start();
        while (true) {

            System.out.print("input :");
            String str = in.nextLine();
            TimeThread.timeStart = System.currentTimeMillis();
            //th.interrupt();
            fw.write(new java.util.Date()+" "+str);
            fw.write("\n");
            fw.flush();
            if ("quit".equals(str)) {
                break;
            }
        }
        fw.close();
    }

    static class TimeThread extends Thread {
        public static long timeStart;

        @Override
        public void run() {
            while (true) {
                try {
                    Thread.sleep(2 * 1000);
                    if (System.currentTimeMillis() - timeStart > 10 * 1000)
                        System.exit(0);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
